package com.gjy.kafka.k10;

import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.header.internals.RecordHeader;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-10-03 10:50:10
 */
public class KafkaUtil {

    /**
     * 创建headers列表
     */
    public static List<Header> createHeaders(String... keyValues) {
        List<Header> headers = new ArrayList<>();
        for (int i = 0; i < keyValues.length; i += 2) {
            if (i + 1 < keyValues.length) {
                headers.add(new RecordHeader(keyValues[i], keyValues[i + 1].getBytes()));
            }
        }
        return headers;
    }

    /**
     * 生成测试消息列表
     */
    public static List<String> generateTestMessages(int count) {
        List<String> messages = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            messages.add("测试消息-" + i + "-" + System.currentTimeMillis());
        }
        return messages;
    }

}
